package com.gitee.wsl.lang

import kotlin.test.Test
import kotlin.test.assertEquals
import kotlin.test.assertFailsWith
import kotlin.test.assertTrue


class PriceDecimalTest {
    @Test 
    fun `operators & string`() {
        assertEquals(20.priceDecimal.toString(),"20")
        assertEquals((3.priceDecimal * 5).toString(),"15")
        assertEquals((3.priceDecimal / 5.0).toString(),"0.60")
        assertEquals((10.priceDecimal / 8).toString(),"1.25")
        assertEquals((100.priceDecimal / 97.priceDecimal).toString(),"1.03")
        assertEquals((100.priceDecimal / 87.priceDecimal).toString(),"1.15")
        assertEquals((100.priceDecimal / 87).toString(),"1.15")
        assertEquals(((-100).priceDecimal / 87).toString(),"-1.15")
        assertEquals((1.05.priceDecimal / 1.05.priceDecimal).toString(),"1")
        assertEquals(100.priceDecimal % 87.priceDecimal,13.priceDecimal)
        assertEquals((10.05.priceDecimal % 8.03.priceDecimal).toString(),"2.02")
        assertEquals("1.33".priceDecimal.toString(),"1.33")
        assertEquals("1.2".priceDecimal.toString(),"1.20")
        assertEquals("145".priceDecimal.toString(),"145")
        assertEquals((-10).priceDecimal,"-10".priceDecimal)
        assertEquals("-123.456".priceDecimal,"-123.46".priceDecimal)
        assertEquals(((-0.97).priceDecimal).toString(),"-0.97")
    }

    @Test fun `min & max`() {
        assertEquals(PriceDecimal.MAX_VALUE.toString(),"92233720368547758.07")
        assertEquals(PriceDecimal.MIN_VALUE.toString(),"-92233720368547758.08")
    }

    @Test fun `inc & dec`() {
        var x = 1.priceDecimal
        assertEquals(++x,2.priceDecimal)
        assertEquals(--x,1.priceDecimal)
    }

    @Test fun absoluteValue() {
        assertEquals(1.priceDecimal.absoluteValue,1.priceDecimal)
        assertEquals((-1).priceDecimal.absoluteValue,1.priceDecimal)
    }

    @Test fun sign() {
        assertEquals("0.01".priceDecimal.sign,1)
        assertEquals(PriceDecimal.ZERO.sign,0)
        assertEquals("-0.01".priceDecimal.sign,-1)
    }

    @Test fun overflow() {
        assertFailsWith(ArithmeticException::class) { PriceDecimal.MAX_VALUE * 2.priceDecimal }
        assertFailsWith(ArithmeticException::class) { PriceDecimal.MAX_VALUE + 1.priceDecimal }
        assertFailsWith(ArithmeticException::class) { PriceDecimal.MIN_VALUE - 1.priceDecimal }
    }

    @Test
    fun compareTo() {
        assertTrue(1.priceDecimal > 0.5.priceDecimal)
        assertTrue(2.priceDecimal < 2.5.priceDecimal)
        assertEquals(1.priceDecimal.compareTo(1.00.priceDecimal),0)
    }

    @Test
    fun percent() {
        assertEquals(200.priceDecimal percent 20.priceDecimal,40.priceDecimal)
    }

    
}
